<?php
require_once 'Donnees/CompteEpargneData.php';

class CompteEpargneAcces  {

	public function create(CompteEpargneData $unCompteEpargneData){
		$requete = "INSERT INTO compteepargne VALUES('','".$unCompteEpargneData->getIdClient()."','".$unCompteEpargneData->getSolde()."','".$unCompteEpargneData->getPlafondMaximum()."')";
		mysql_query($requete);
		$unCompteEpargneData->setId(mysql_insert_id());
		return $unCompteEpargneData;

	}
	public function read($id){
		// retourne CompteEpargneData
	}
	public function findOneByIdClient($idClient)
	{
		$requete = "SELECT * FROM compteepargne WHERE idClient='".$idClient."'";
		$reponse = mysql_query($requete);
		$compte = mysql_fetch_array($reponse);
		if(is_bool($compte)) return false;
		$compteEpargneData = new CompteEpargneData();
		$compteEpargneData->setId($compte['id']);
		$compteEpargneData->setIdClient($compte['idClient']);
		$compteEpargneData->setSolde($compte['solde']);
		$compteEpargneData->setPlafondMaximum($compte['plafondMaximum']);
		return $compteEpargneData;
	}

	public function update(CompteEpargneData $unCompteEpargneData){
		$requete = "UPDATE compteepargne SET idClient='".$unCompteEpargneData->getIdClient()."', solde='".$unCompteEpargneData->getSolde()."', plafondMaximum='".$unCompteEpargneData->getPlafondMaximum()."' WHERE id='".$unCompteEpargneData->getId()."'";
		mysql_query($requete);
		return $unCompteEpargneData;


	}
	public function delete(CompteEpargneData $unCompteEpargneData){

	}
}


?>